package javafx179labs.sheypak.lab4;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.animation.Timeline;
import javafx.scene.transform.Rotate;
import javafx.scene.input.MouseEvent;


var leftHandAngle = 0;
var rightHandAngle = 0;

//objects
var head : Circle = Circle{
    radius: 40
    centerX:200
    centerY:50
    fill: Color.YELLOW
    scaleY: 0.7
    onMouseClicked: function(evt: MouseEvent):Void{
        timeline.playFromStart();
    }
}

var body : Rectangle = Rectangle{
    x:185
    y:75
    width:30
    height:70
    fill: Color.BLUE
}

var leftHand : Rectangle = Rectangle{
    x:140
    y:95
    width: 45
    height: 10
    fill: Color.BROWN
    transforms: [
            Rotate{
                pivotX:185
                pivotY:95
                angle:bind leftHandAngle
            }
    ]
}

var rightHand : Rectangle = Rectangle{
    x:215
    y:95
    width: 45
    height: 10
    fill: Color.BROWN
    transforms: [
            Rotate{
                pivotX:215
                pivotY:95
                angle: bind rightHandAngle
            }
    ]
}
var b : Boolean = true;
//timeline stuff
var timeline : Timeline = Timeline{
    repeatCount:4
    autoReverse:true
    keyFrames: [
         at(0s){
            leftHandAngle => 30;
            rightHandAngle => -30;
            b => true;
         }
         at(2s){
            leftHandAngle => 60;
            rightHandAngle => -60;
           
         }
         at(3s){
            leftHandAngle => 60;
            rightHandAngle => -60;
         }

         at(4s){
            leftHandAngle => 90;
            rightHandAngle => -90;
         }
        ]
}




Stage {
    title: "Application title"
    width: 500
    height: 500
    scene: Scene {
        content: [
            head,
            body,
            leftHand,
            rightHand
        ]
    }
}